<?php
namespace plugins\sms\lib\aliyun_sms;
use think\Config;
use plugins\sms\lib\Common;

class AliyunSms 
{
    public $name = '阿里云短信服务商';
    
    const URL = "/zyapi/sms/sendSms";
    
    //阿里云发送方法
    public function send( $sendData )
    {
        //构造请求参数
        $post = [
            'key'           => cmf_var_isset( $sendData [ 'proof' ] , 'key' ),
            'key_secret'    => cmf_var_isset( $sendData [ 'proof' ] , 'key_secret' ),
            'mobile'        => cmf_var_isset( $sendData , 'mobile' ),
            'model'         => cmf_var_isset( $sendData , 'mb_number' ),
            'sign'          => cmf_var_isset( $sendData , 'mb_sign'),
            'content'       => cmf_var_isset( $sendData , 'content' )
        ];
        
        
        $url = Config::get( 'admin_module_config.api_host' ).self::URL;
        
        $res = Common::curlPost( $url , http_build_query( $post ) );

        $res = json_decode( $res , true );
        
        if( $res ){
            Common::updateSmsRecordStatus( $sendData[ 'record_id' ] , 2 );
            return api_result( ( $res['status'] == 'success' ? true : false ) , $res [ 'message' ]  );
        }
        Common::updateSmsRecordStatus( $sendData[ 'record_id' ] , 1 );
        return api_result( false , '请求成功,远程接口返回了未知错误,请检查(阿里云短信服务商参数配置)'  );
   
    }
}